import 'package:flutter/material.dart';

import 'HomeDemo.dart';
import 'ImageDemo.dart';
import 'layout_page.dart';
class MainPage extends StatefulWidget {
  const MainPage({super.key});

  @override
  State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  var _brightness = Brightness.dark;
  var themeStr = "黑";
  var _currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        useMaterial3: true,
        brightness: _brightness,
      ),
      home: Scaffold(
        bottomNavigationBar: BottomNavigationBar(
          currentIndex: _currentIndex,
          onTap: (index) {
            setState(() {
              _currentIndex = index;
            });
          },
          items: const [
            BottomNavigationBarItem(
                icon: Icon(Icons.home, color: Colors.grey),
                activeIcon: Icon(Icons.home, color: Colors.green),
                label: "Home"),
            BottomNavigationBarItem(
                icon: Icon(Icons.list, color: Colors.grey),
                activeIcon: Icon(Icons.list, color: Colors.green),
                label: "List"),
            BottomNavigationBarItem(
                icon: Icon(Icons.settings, color: Colors.grey),
                activeIcon: Icon(Icons.settings, color: Colors.green),
                label: "Settings"),
          ],
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            setState(() {
              if (_brightness == Brightness.dark) {
                _brightness = Brightness.light;
                themeStr = "浅";
              } else {
                _brightness = Brightness.dark;
                themeStr = "黑";
              }
            });
          },
          child: Text(themeStr),
        ),
        body: RefreshIndicator(
            child: ListView(children: [getPage(_currentIndex)]),
            onRefresh: _handleRefresh),
      ),
    );
  }

  Future _handleRefresh() async {
    await Future.delayed(Duration(seconds: 1));
  }

  getPage(int currentIndex) {
    switch (currentIndex) {
      case 0:
        return Homedemo();
      case 1:
        return Imagedemo();
      default:
        return const LayoutPage();
    }
  }
}
